package com.fancy.learncenter.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.activity.H5Activity;
import com.fancy.learncenter.activity.NewsDetailActivity;
import com.fancy.learncenter.activity.NewsH5Activity;
import com.fancy.learncenter.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.adapter.base.CustomViewHold;
import com.fancy.learncenter.bean.TopNewsDataBean;
import com.fancy.learncenter.common.Constant;
import com.fancy.learncenter.common.MyApplication;
import com.fancy.learncenter.utils.LogUtil;
import com.superservice.lya.R;

import java.util.ArrayList;

/**
 * Created by hyy on 2018/2/24.
 * Explain activity as
 */

public class TopNewsAdapter extends CommonRecycleViewAdapter<TopNewsDataBean> {
    public TopNewsAdapter(Context mContext, ArrayList<TopNewsDataBean> itemDatas) {
        super(mContext, R.layout.fragment_material_item, itemDatas);
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final TopNewsDataBean item, int position) {
        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
        simpleDraweeView.setImageURI(item.getImgsrc());

        TextView title = customViewHold.getView(R.id.title);
        title.setText(item.getTitle());

        TextView view_num = customViewHold.getView(R.id.num);
        view_num.setText(item.getTag_name());

        TextView time = customViewHold.getView(R.id.time);
        time.setText(item.getAdd_time());


        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(mContext, NewsH5Activity.class);
                intent.putExtra(H5Activity.URL_KEY, getLoadUrl(item.getUrl()));
                intent.putExtra("topLineId", item.getId());
                mContext.startActivity(intent);

            }
        });
    }


    private String getLoadUrl(String url) {

        StringBuilder sbUrl = new StringBuilder();
        sbUrl.append(url);

        if (sbUrl.toString().contains("?")) {
            sbUrl.append("&fromapp_user_id=" + MyApplication.userId);
        } else {
            sbUrl.append("?fromapp_user_id=" + MyApplication.userId);
        }
        return sbUrl.toString();
    }

}
